package com.itheima.tliasmanager.service.impl;

import com.itheima.tliasmanager.mapper.EmpMapper;
import com.itheima.tliasmanager.pojo.dto.GenderCount;
import com.itheima.tliasmanager.pojo.dto.JobCount;
import com.itheima.tliasmanager.pojo.vo.JobVo;
import com.itheima.tliasmanager.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Slf4j
@Service
public class ReportServiceImpl implements ReportService {


    @Autowired
    private EmpMapper empMapper;

    /**
     * 获取员工职位统计数据
     * @return
     */
    @Override
    public JobVo empJobReport() {
        //1.调用mapper层方法，获取职位统计数据
        List<JobCount> jobCountList = empMapper.countByJob();

        //2.处理mapper层查询结果，封装成JobVo （map映射方法，将集合映射成另外一个集合）
        List<String> jobList = jobCountList.stream().map(jc -> jc.getJob()).collect(Collectors.toList());
        List<Integer> dataList = jobCountList.stream().map(jc -> jc.getCount()).collect(Collectors.toList());

        /*//3.将jobList中的数值转换成对应的职位名称
        for (int i = 0; i < jobList.size(); i++) {
            String jobName = jobList.get(i);
            switch (jobName){
                case "1":
                    jobList.set(i,"班主任");
                    break;
                case "2":
                    jobList.set(i,"讲师");
                    break;
                case "3":
                    jobList.set(i,"学工主管");
                    break;
                case "4":
                    jobList.set(i,"教研主管");
                    break;
                default:
                    jobList.set(i,"咨询师");
            }
        }*/

        return new JobVo(jobList, dataList);
    }

    /**
     * 获取员工性别统计数据
     * @return
     */
    @Override
    public List<GenderCount> empGenderReport() {

        //1.调用mapper层方法，获取性别统计数据
        List<GenderCount> genderCountList = empMapper.countByGender();

        //2.返回结果
        return genderCountList;
    }
}
